import http from '@/axios/http.js';
import baseUrl from '@/constant/index/apiUrl.js';
//import mock from '@/mock/api/index/data.js';

const env = import.meta.env.VITE_MODE_NAME;

export default {
	//首页hotList列表查询
	getHotList() {
		if (env == 'development') {
			return http.get(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.hot);
		} else if (env == 'test') {
			return http.get(import.meta.env.VITE_API_URL_SEARCH + baseUrl.hot);
		}
	},
	//首页新闻查询
	getNewsList() {
		if (env == 'development') {
			return http.get(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.news);
		} else if (env == 'test') {
			return http.get(import.meta.env.VITE_API_URL_HOME + baseUrl.news);
		}
	},
	//首页新品速递查询
	getNewProductsList() {
		if (env == 'development') {
			return http.get(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.newProducts);
		} else if (env == 'test') {
			return http.get(import.meta.env.VITE_API_URL_HOME + baseUrl.newProducts);
		}
	},
	//到首页时有token,根据算法推荐模型
	getNewProductsListByuId(uId){
		if (env == 'development') {
			return http.getByparams(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.newProducts,{params:{uId}});
		} else if (env == 'test') {
			return http.getByparams(import.meta.env.VITE_API_URL_HOME + baseUrl.newProducts,{params:{uId}});
		}
	},
	//登录表单验证码
	getCaptcha(){
		if (env == 'development') {
			return http.get(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.captCha,{
				time:new Date().getTime()
			});
		}
		else if (env == 'test') {
			return http.get(import.meta.env.VITE_API_URL_HOME + baseUrl.captCha,{
				time:new Date().getTime()
			});
		}
	},
	//登录
	toLogin(loginForm){
		if (env == 'development') {
			return http.post(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.login,loginForm);
		}
		else if (env == 'test') {
			return http.post(import.meta.env.VITE_API_URL_SSO + baseUrl.login,loginForm);
		}
	},
	//退出登录
	logOut(){
		if (env == 'development') {
			return http.post(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.logout);
		}
		else if (env == 'test') {
			return http.post(import.meta.env.VITE_API_URL_SSO + baseUrl.logout);
		}
	},
	//获取登录的用户信息
	getUserInfo(uid) {
		if (env == 'development') {
			return http.get(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.userInfo + uid);
		}
		else if (env == 'test') {
			return http.get(import.meta.env.VITE_API_URL_INFO + baseUrl.userInfo + uid);
		}
	},
	//查询
	getSearchList(pageDto,keyword){
		if (env == 'development') {
			return http.post(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.search + '?keyword='+keyword,pageDto);
		} else if (env == 'test') {
			return http.post(import.meta.env.VITE_API_URL_SEARCH + baseUrl.search + '?keyword='+keyword,pageDto);
		}
	},
	//注册
	toRegister(registerForm){
		if (env == 'development') {
			return http.post(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.register,registerForm);
		}
		else if (env == 'test'){
			return http.post(import.meta.env.VITE_API_URL_SSO + baseUrl.register,registerForm);
		}
	},
	//注册表单验证码
	getSmsCaptcha(telePhone){
		if (env == 'development') {
			return http.getByparams(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.smscaptCha,{params:{telePhone}});
		}
		else if (env == 'test') {
			return http.getByparams(import.meta.env.VITE_API_URL_HOME + baseUrl.smscaptCha,{params:{telePhone}});
		}
	},
	//删除redis中token
	deleteUserToken(uId){
		if (env == 'development') {
			return navigator.sendBeacon(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.deleteUserToken + uId);
			//return http.delete(import.meta.env.VITE_API_URL_GATEWAY + baseUrl.deleteUserToken + uId);
		}
		else if (env == 'test') {
			return http.delete(import.meta.env.VITE_API_URL_SSO + + baseUrl.deleteUserToken + uId);
		}
	}
}
